-
Notifications
You must be signed in to change notification settings - Fork 240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ignore unknown elements #121
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the help! I hope my comments aren't too pedantic 🙇♂️
SVGEngine.mm
Outdated
while(xmlTextReaderRead(_xmlReader) == 1) { | ||
int const type = xmlTextReaderNodeType(_xmlReader); | ||
const char * const tag = (char *)xmlTextReaderConstName(_xmlReader); | ||
|
||
CGPathRef path = NULL; | ||
if(type == XML_READER_TYPE_ELEMENT && strcasecmp(tag, "path") == 0) | ||
if(type == XML_READER_TYPE_ELEMENT && strcasecmp(tag, "svg") == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's insert a comment here along the lines of
if (tag==<svg>) {
// Prevent <svg> from being ignored`
} else ...```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
SVGEngine.mm
Outdated
@@ -125,7 +133,9 @@ @interface SVGAttributeSet () { | |||
pushGroup(readAttributes()); | |||
else if(type == XML_READER_TYPE_END_ELEMENT) | |||
popGroup(); | |||
} | |||
} else if(type == XML_READER_TYPE_ELEMENT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use curlies {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally this check should just be if (type == XML_READER_TYPE_ELEMENT && !xmlTextReaderIsEmptyElement(_xmlReader))
skipping the next if statement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is changing to be a single-line branch I presume that you don't want curlies around it, in order to match the rest of the code here?
SVGEngine.mm
Outdated
@@ -103,12 +103,20 @@ @interface SVGAttributeSet () { | |||
valueOptions:NSMapTableStrongMemory]; | |||
NSMutableArray * const paths = [NSMutableArray new]; | |||
|
|||
unsigned int depthWithinUnknownElement = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file uses NSUInteger
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
SVGEngine.mm
Outdated
while(xmlTextReaderRead(_xmlReader) == 1) { | ||
int const type = xmlTextReaderNodeType(_xmlReader); | ||
const char * const tag = (char *)xmlTextReaderConstName(_xmlReader); | ||
|
||
CGPathRef path = NULL; | ||
if(type == XML_READER_TYPE_ELEMENT && strcasecmp(tag, "path") == 0) | ||
if(type == XML_READER_TYPE_ELEMENT && strcasecmp(tag, "svg") == 0) { | ||
} else if(depthWithinUnknownElement > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd be a bit more readable if this check came first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More correct too, 💯
I'm not sure if there are any wrapper tags that we wouldn't want to ignore. Best to be careful here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, just saw that this PR got raised.
I'll go through and make the changes soon.
SVGEngine.mm
Outdated
while(xmlTextReaderRead(_xmlReader) == 1) { | ||
int const type = xmlTextReaderNodeType(_xmlReader); | ||
const char * const tag = (char *)xmlTextReaderConstName(_xmlReader); | ||
|
||
CGPathRef path = NULL; | ||
if(type == XML_READER_TYPE_ELEMENT && strcasecmp(tag, "path") == 0) | ||
if(type == XML_READER_TYPE_ELEMENT && strcasecmp(tag, "svg") == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
SVGEngine.mm
Outdated
while(xmlTextReaderRead(_xmlReader) == 1) { | ||
int const type = xmlTextReaderNodeType(_xmlReader); | ||
const char * const tag = (char *)xmlTextReaderConstName(_xmlReader); | ||
|
||
CGPathRef path = NULL; | ||
if(type == XML_READER_TYPE_ELEMENT && strcasecmp(tag, "path") == 0) | ||
if(type == XML_READER_TYPE_ELEMENT && strcasecmp(tag, "svg") == 0) { | ||
} else if(depthWithinUnknownElement > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More correct too, 💯
SVGEngine.mm
Outdated
@@ -103,12 +103,20 @@ @interface SVGAttributeSet () { | |||
valueOptions:NSMapTableStrongMemory]; | |||
NSMutableArray * const paths = [NSMutableArray new]; | |||
|
|||
unsigned int depthWithinUnknownElement = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
02e2c31
to
cf9525a
Compare
Comments addressed (I think) in a Of the "container" and "structural" elements, I think the only one that could be correctly handled by rendering its contents into the document would be |
Changes look good. Could you add |
cf9525a
to
264ed73
Compare
Just a quick headsup: we now have a CHANGELOG to make it easier to keep track of new features and bugs, and to credit our contributors. It'd be great if your PR also updates it. |
A test suite too! I'll make up some cases for this change. |
264ed73
to
d1976bb
Compare
The tests are pretty cheesy but they do test the functionality. :-) |
Also it looks like the ordering of attributes in the produced SVG string is not fixed? The ordering does seem deterministic, as the tests pass once the magic ordering for that testcase is determined, but it's not predictable? |
The order is undefined. |
Hm, indeed. |
You could |
d1976bb
to
9ca0d9c
Compare
9ca0d9c
to
87e6b71
Compare
let paths = SVGBezierPath.paths(fromSVGString: svgString) | ||
XCTAssertEqual(paths.count, 1) | ||
|
||
guard let path = paths.first else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if XCTAssertEqual(paths.count, 1)
passes, then we know that paths.first != nil
, so this guard let
is redundant and it's safe to do path!.bounds
below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured that bailing after failing the assertion was friendlier than hitting a fatal error and breaking the whole test run in the case that we don't parse any paths out of the svg?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an individual test's execution stops as soon as an assertion fails, so if we don't parse any paths out of the svg we'll duly fail the assertion on line 101 and we're guaranteed not to execute the code with the force unwrap.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. That’s not how Xcode (9.3) behaves on my computer and I can’t see .continueAfterFailure
being set anywhere. Is that a global configuration option in Xcode?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, sorry, you're absolutely right, I hadn't set .continueAfterFailure
to false
I have now: 1c014fa
let paths = SVGBezierPath.paths(fromSVGString: svgString) | ||
XCTAssertEqual(paths.count, 1) | ||
|
||
guard let path = paths.first else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto as above.
If ordering of attributes is undefined, this could fail even if parsing and generation are done properly, no? |
Testing that the I thought of doing something like:
but if attributes can be in order, then this test will unduly fail if we generated So we could simplify the tests to this extent:
Do you find that'd be at all useful ? |
Oh, I meant specifically these tests for this functionality being easily changed to just test the attributes. I think the existing string representation tests certainly do have a place and IMO they're most useful remaining as holistic document tests, as long as the contents of the documents can be given a stable ordering. |
Please let me know if there are any other changes you'd like to make to this PR, as I'd like to merge it within a couple of days. I can take care of removing the |
merged via fc4c0af |
See: #118